package com.example.demo;


import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Field;

@RestController
@RequiredArgsConstructor
@RequestMapping("/flexi-api/test")
public class TestController {
    /**
     * 提交模版
     */
    @PostMapping("/test_createv2")
    public void saveOrUpdatev2(@RequestBody @Validated FeatureTemplateClassGenerateReq featureTemplate) throws Exception {
        DynamicFeatureClassGenerator.generateFeatureClassFromJson(featureTemplate);

    }

    @PostMapping("/test_createv1")
    public void saveOrUpdatev1(@RequestBody @Validated FeatureTemplateClassGenerateReq featureTemplate) throws Exception {
        DynamicFeatureClassGeneratorV1.generateFeatureClassFromJson(featureTemplate);

    }

    @GetMapping("/testv1")
    public void saveOrUpdatev1(String className) throws Exception {
        Class<?> aClass = Class.forName(className);
        for (Field declaredField : aClass.getDeclaredFields()) {
            System.out.println("declaredField------------"+declaredField.getName());
        }
    }

    @GetMapping("/testv2")
    public void saveOrUpdatev2(String className) throws Exception {
        Class<?> aClass = RuleClassUtils.forName(className);
        for (Field declaredField : aClass.getDeclaredFields()) {
            System.out.println("declaredField------------"+declaredField.getName());
        }
    }

    @GetMapping("/testv3")
    public void printPath() throws Exception {
        System.out.println(TestController.class.getProtectionDomain().getCodeSource().getLocation().getPath());
    }

    public static void main(String[] args) {

    }


}
